package com.woniu.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 消息队列配置类
 */
@Configuration
public class RabbitMqConfig {

    //采购交换机器
    @Bean(name = "purchase_exchange")
    public Exchange getExchange(){
        return ExchangeBuilder.directExchange("purchase_exchange").durable(true).build();
    }
    //声明队列
    @Bean(name = "purchase_queue")
    public Queue getQueue(){
        return QueueBuilder.durable("purchase_queue").build();
    }
    //绑定队列和交换机
    @Bean
    public Binding binding(@Qualifier("purchase_exchange") Exchange exchange, @Qualifier("purchase_queue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("purchase.examine").noargs();
    }

    //生产交换机器
    @Bean(name = "pro_exchange")
    public Exchange getExchange2(){
        return ExchangeBuilder.directExchange("pro_exchange").durable(true).build();
    }
    //声明队列
    @Bean(name = "pro_queue")
    public Queue getQueue2(){
        return QueueBuilder.durable("pro_queue").build();
    }
    //绑定队列和交换机
    @Bean
    public Binding binding2(@Qualifier("pro_exchange") Exchange exchange, @Qualifier("pro_queue") Queue queue){
        return BindingBuilder.bind(queue).to(exchange).with("pro.plan").noargs();
    }

}
